package com.bocai.yuweiwangluo.base;

import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.baidu.mapapi.SDKInitializer;
import com.tencent.bugly.crashreport.CrashReport;

import cn.jpush.android.api.JPushInterface;
import cn.sharesdk.framework.ShareSDK;

/**
 * Created by win7 on 2015/12/3.
 */
public class MyApplication extends Application {
    private static Context context;
    public static final String SHARESDK_APPKEY = "d5b945010273";
    /** BaseApplication 单例 */
    public static MyApplication appInstance = null;
    public static boolean isAppRuning = false;
    public static  boolean isNetwork;
    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        CrashReport.initCrashReport(getApplicationContext(), "900034946", false);
//        GetLocationInfo_BD.initLocation(context);
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        SDKInitializer.initialize(getApplicationContext());
        /** shareSDK分享**/
        ShareSDK.initSDK(this,SHARESDK_APPKEY);
        /** 利用百度地图定位 **/
		/*---------- zk  增加 --------------*/
        appInstance = this;
        isAppRuning = true;
        isNetwork=checkNetworkAvailable(getApplicationContext());
    }
    /** 判断是否有网*/
    public  boolean checkNetworkAvailable(Context context) {
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity == null) {
            return false;
        } else {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) {
                for (int i = 0; i < info.length; i++) {
                    if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                        NetworkInfo netWorkInfo = info[i];
                        if (netWorkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                            return true;
                        } else if (netWorkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                            return true;
                        }
                    }
                }
            }
        }

        return false;

    }

    public static MyApplication getInstance() {
        return appInstance;
    }
}
